package cn.stylefeng.guns.modular.base.item.controller;

import cn.stylefeng.guns.modular.base.item.entity.Item;
import cn.stylefeng.guns.modular.base.item.pojo.request.ItemRequest;
import cn.stylefeng.guns.modular.base.item.service.ItemService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基础数据-存货档案控制器
 *
 * @author caoxf
 * @since 2023/11/20 22:56
 */
@RestController
@ApiResource(name = "基础数据-存货档案")
public class ItemController {

    @Resource
    private ItemService itemService;

    /**
     * 添加基础数据-存货档案
     *
     * @author caoxf
     * @since 2023/11/20 22:56
     */
    @PostResource(name = "添加基础数据-存货档案", path = "/item/add")
    public ResponseData<Item> add(@RequestBody @Validated(ItemRequest.add.class) ItemRequest itemRequest) {
        itemService.add(itemRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除基础数据-存货档案
     *
     * @author caoxf
     * @since 2023/11/20 22:56
     */
    @PostResource(name = "删除基础数据-存货档案", path = "/item/delete")
    public ResponseData<?> delete(@RequestBody @Validated(ItemRequest.delete.class) ItemRequest itemRequest) {
        itemService.del(itemRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 批量删除基础数据-存货档案
     *
     * @author caoxf
     * @since 2023/11/20 22:56
     */
    @PostResource(name = "批量删除基础数据-存货档案", path = "/item/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) ItemRequest itemRequest) {
        itemService.batchDelete(itemRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑基础数据-存货档案
     *
     * @author caoxf
     * @since 2023/11/20 22:56
     */
    @PostResource(name = "编辑基础数据-存货档案", path = "/item/edit")
    public ResponseData<?> edit(@RequestBody @Validated(ItemRequest.edit.class) ItemRequest itemRequest) {
        itemService.edit(itemRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看基础数据-存货档案详情
     *
     * @author caoxf
     * @since 2023/11/20 22:56
     */
    @GetResource(name = "查看基础数据-存货档案详情", path = "/item/detail")
    public ResponseData<Item> detail(@Validated(ItemRequest.detail.class) ItemRequest itemRequest) {
        return new SuccessResponseData<>(itemService.detail(itemRequest));
    }

    /**
     * 获取基础数据-存货档案列表
     *
     * @author caoxf
     * @since 2023/11/20 22:56
     */
    @GetResource(name = "获取基础数据-存货档案列表", path = "/item/list")
    public ResponseData<List<Item>> list(ItemRequest itemRequest) {
        return new SuccessResponseData<>(itemService.findList(itemRequest));
    }

    /**
     * 获取基础数据-存货档案列表（带分页）
     *
     * @author caoxf
     * @since 2023/11/20 22:56
     */
    @GetResource(name = "获取基础数据-存货档案列表（带分页）", path = "/item/page")
    public ResponseData<PageResult<Item>> page(ItemRequest itemRequest) {
        return new SuccessResponseData<>(itemService.findPage(itemRequest));
    }

}
